// @(#)excep.cc
// Time-stamp: <2009-01-13 17:05:12 lancer>
// Copyright 2008 Julian Qian
// Author: root@localhost.localdomain
// Version: $Id: excep.cc,v 0.0 2008/11/21 03:58:52 root Exp $
// Keywords: 

#include "excep.hh"
#include <string.h>
#include <errno.h>

using namespace std;

Excep::Excep(const Excep& e) throw() :
    exception(e), what_(e.what_){
    // what_ = "filename: " + __FILE__ + "line: " + __LINE__;
}

Excep&
Excep::operator=(const Excep& rhs) throw(){
    what_ = rhs.what_;
    return *this;
}

const char*
Excep::what() const throw(){
    return what_.c_str();
}

SocketException::SocketException(const char* w = "") throw(){
    string result_(w);
    result_ += " : ";
    result_ += strerror(errno);
    whatis(result_.c_str());
}

LoginFailed::LoginFailed(const char* u = "", int r = 0) throw() {
    string result_ = "RESULT: ";
    switch(r){
    case 0:
        result_ += "Login successfully!";
        break;
    case 1:
        result_ += "Connect to system database failed!";
        break;
    case 2:
        result_ += "Your login password cannot be empty!";
        break;
    case 3:
        result_ += "This account does not exist!";
        break;
    case 4:
        result_ += "Web service is closed now, can not communicate it.";
        break;
    case 5:
        result_ += "Your password is uncorrect.";
        break;
    case 6:
        result_ += "Your message quantity is limited.";
        break;
    case 7:
        result_ += "Exceptional, maybe your account has logined.";
        break;
    case 10:
        result_ += "You cannot login from two clients at one time.";
        break;
    default:
        result_ += "Unknown";
        break;
    }
    whatis(result_.c_str());
}
